home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _3DF914F542DC4B32AB781778AF16EA19 < prev    next >
Encoding:
Text File  |  2004-01-06  |  7.6 KB  |  216 lines

  1. Script:LoadScript("scripts/GUI/HudCommon.lua");
  2.  
  3. Hud.objectives={};
  4.  
  5. function Hud:PushObjective(pos,text)
  6.     --check if the objective is already present
  7.     for i,val in self.objectives do
  8.         if(val.text==text)then 
  9.             return
  10.         end
  11.     end
  12.     self.objectives[getn(self.objectives)+1]={pos=new(pos),text=text,completed=nil}
  13. end
  14. -----------------------------------------------------------------------------
  15. function Hud:FlashObjectives()
  16.     self.objectives={}
  17. end
  18.  
  19. -- [marco] remove it based on objective name
  20. -----------------------------------------------------------------------------
  21. function Hud:CompleteObjective(text)
  22.     for i,val in self.objectives do
  23.         if(val.text==text)then
  24.             val.completed=1;
  25.             -- break --in editor mode, there can be more than 1 with the same name
  26.         end
  27.     end
  28. end
  29.  
  30.  
  31. -----------------------------------------------------------------------------
  32. function Hud:OnInit()
  33.     System:Log("Hud:OnInit()");
  34.     -- concentration
  35. --    if (s_SFXVolume) then
  36. --        g_GlobalSFXVolume=tonumber(s_SFXVolume);
  37. --    else
  38. --        g_GlobalSFXVolume=0;
  39. --    end
  40.  
  41.     self:CommonInit();    
  42. end
  43. -----------------------------------------------------------------------------
  44. function Hud:OnUpdate()
  45.     local player=_localplayer;
  46.     
  47.     -- Update Dynamic music.
  48.     self:UpdateDynamicMusic();
  49.  
  50.     -- [marco] The environment can be affected by lightning, which blinds any player 
  51.     -- using Night Vision for a brief period. In case of the night vision
  52.     -- is done in the above call.
  53.     if(tonumber(cl_display_hud)~=0)then
  54.         if(player and player.classname=="Player")then
  55.         
  56.             ClientStuff.vlayers:DrawOverlay();
  57.             
  58.                                     
  59.             -- [kirill] blinding player with flashlight
  60.             
  61.             local    scrPos =player.cnt:GetBlindScreenPos();
  62.             local curBlind = 10;        
  63.             local curW = 200;
  64.             local curH = 150;
  65.                                                             
  66.             while( scrPos ~= nil ) do
  67.                 curBlind = scrPos.z;        
  68.                 curW = 200 + 450 * curBlind;
  69.                 curH = 150 + 450 * curBlind;
  70.     --            System:DrawImageColor( self.flashlight_blinding, scrPos.x-curW*.5, scrPos.y-curH*.5, curW, curH, 5, curBlind,curBlind,curBlind,curBlind);                        
  71.                 System:DrawImageColor( self.flashlight_blinding, scrPos.x-curW*.5, scrPos.y-curH*.5, curW, curH, 4, 1, 1, 1, curBlind);
  72.                 scrPos = player.cnt:GetBlindScreenPos();
  73.             end    
  74.             
  75.               -- Display on screen damage fx                                     
  76.             if(hud_screendamagefx == "1" and g_gore ~= "0") then
  77.               if (not ClientStuff.vlayers:IsActive("SmokeBlur") and not ClientStuff.vlayers:IsFading("SmokeBlur")) then                                              
  78.                 -- check damage/hits...
  79.                 if(self.hitdamagecounter>0) then
  80.                   -- [tiago] testing blury/bloody screen fx
  81.                   System:SetScreenFx("ScreenBlur", 1);                            
  82.                   self.hitdamagecounter=self.hitdamagecounter - _frametime*3.5;
  83.                   System:SetScreenFxParamFloat("ScreenBlur", "ScreenBlurAmount", self.hitdamagecounter/10.0);
  84.                 else
  85.                   System:SetScreenFx("ScreenBlur", 0);
  86.                   self.hitdamagecounter=0;
  87.                 end                                              
  88.               end
  89.             end
  90.  
  91.     
  92.             -- [lennert] When a loud noise occurs (grenade etc.), the player will be deafened. Client-effect only...
  93.             if (self.deaf_time) then
  94.                 --System:LogToConsole("deafened:"..self.deaf_time);
  95.  
  96.                 local fSoundScale=1;
  97.  
  98.                 -- [marco] gives a couple of seconds before starting
  99.                 -- the deafness so that the player will ear the explosion
  100.                 if (self.deaf_time<(self.initial_deaftime-1.7)) then
  101.  
  102.                     if (self.deaf_time<self.deafness_fadeout_time) then
  103.                         fSoundScale=self.deaf_time/self.deafness_fadeout_time;
  104.                     end
  105.                     Sound:SetGroupScale(SOUNDSCALE_DEAFNESS, 1-fSoundScale);
  106.                     if (not Sound:IsPlaying(self.EarRinging)) then
  107.                         --System:Log("start ear ringing");
  108.                         Sound:PlaySound(self.EarRinging);
  109.                     end
  110.                     Sound:SetSoundVolume(self.EarRinging, fSoundScale*255);
  111.                 end
  112.  
  113.                 self.deaf_time=self.deaf_time-_frametime;
  114.                 if (self.deaf_time<=0) then
  115.                     self.deaf_time=nil;
  116.                     Sound:StopSound(self.EarRinging);
  117.                     Sound:SetGroupScale(SOUNDSCALE_DEAFNESS, 1);
  118.                 end
  119.             end
  120.                 
  121.             --infos
  122.             %Game:SetHUDFont("hud", "ammo");
  123.             
  124.             --if(not ClientStuff.vlayers:IsActive("Binoculars") and player.cnt.health>0)then
  125.             --    self:DrawCompass(player);
  126.             --end
  127.     
  128.             -- display items
  129.             self:DrawItems(player);            
  130.             -- display stealth meter
  131.             self:DrawStealthMeter(0,567);            
  132.             -- update hud
  133.             self:OnUpdateCommonHudElements();            
  134.                         
  135.             -- GOD O METER-------------------------------------------------
  136.             if(god and (tonumber(god)==1))then                
  137.                 %Game:WriteHudString( 10, 10, "You Wish, Try Harder ",0, 1, 0, 1, 30, 30);
  138.             end
  139.                 
  140.             -- display mission box
  141.             ScoreBoardManager:Render();            
  142.         end        
  143.     end    
  144.     
  145.     
  146.     if(player and player.classname=="Player") then        
  147.         -- only player gets 'panoramic'.. (there's some bug in renderer, i have to set ONE ZERO blending mode, since blending is not reseted for some reason)
  148.          if(hud_panoramic=="1") then                            
  149.             %System:DrawImageColorCoords(self.black_dot, 0, 0, 800, tonumber(hud_panoramic_height), 9, 0, 0, 0, 0.5, 0, 0, 1, 1);    
  150.             %System:DrawImageColorCoords(self.black_dot, 0, 600-tonumber(hud_panoramic_height), 800, tonumber(hud_panoramic_height), 9, 0, 0, 0, 0.5, 0, 0, 1, 1);        
  151.         end        
  152.         
  153.         -- display messages    
  154.         self:MessagesBox();
  155.     end
  156. end
  157.  
  158. -------------------------------------------------------------------------------
  159. -- Available DynamicMusic mood events.
  160. -------------------------------------------------------------------------------
  161. DynamicMusicMoodEvents = {
  162.     Alert = { mood = "Alert",timeout = MM_ALERT_TIMEOUT },
  163.     Suspense = { mood = "Suspense",timeout = MM_SUSPENSE_TIMEOUT },
  164.     NearSuspense = { mood = "NearSuspense",timeout = MM_NEARSUSPENSE_TIMEOUT },
  165.     Combat = { mood = "Combat",timeout = 0 },
  166.     Victory = { mood = "Victory",timeout = 0 }
  167. };
  168.  
  169. -------------------------------------------------------------------------------
  170. -- Controls moods in dynamic music.
  171. -------------------------------------------------------------------------------
  172. function Hud:UpdateDynamicMusic()
  173.     local sneak = AI:GetPerception();
  174.     local moodEvent = nil;
  175.     
  176.     --System:Log( "Sneak="..sneak );
  177.     if (sneak > 110) then
  178.         -- if the AI starts attacking we send a COMBAT-mood event
  179.         moodEvent = DynamicMusicMoodEvents.Combat;
  180.     elseif ((sneak > 0 and sneak <= 110) or (self.EnemyAlerted ~= 0)) then
  181.         -- if the AI starts attacking we send a COMBAT-mood event
  182.         moodEvent = DynamicMusicMoodEvents.Alert;
  183.     elseif (self.EnemyInNearSuspense~=0) then
  184.         -- if the AI is very near we send a NEAR-mood event
  185.         moodEvent = DynamicMusicMoodEvents.NearSuspense;
  186.     elseif (self.EnemyInSuspense~=0) then
  187.         -- if the AI is near we send a SUSPENSE-mood event
  188.         moodEvent = DynamicMusicMoodEvents.Suspense;
  189.     end
  190.     
  191.     if (self.PrevSneakValue) then
  192.         if (self.PrevSneakValue>50) and (sneak==0) and (Sound:IsInMusicMood("Combat") and (self.EnemyAlerted==0)) then
  193.             -- if the sneak value drops instantly from combat to 0 we killed the last guy, so we send a VICTORY-mood event
  194.             --System:Log("VICTORY !!!");
  195.             moodEvent = DynamicMusicMoodEvents.Victory;
  196.         end
  197.     end
  198.     
  199.     if (moodEvent) then
  200.         Sound:AddMusicMoodEvent( moodEvent.mood,moodEvent.timeout );
  201.     end
  202.     
  203.     self.PrevSneakValue = sneak;
  204. end
  205.  
  206.  
  207. -----------------------------------------------------------------------------
  208. function Hud:OnShutdown()
  209.     %System:Log("Hud:OnShutdown()");
  210.     self.EarRinging=nil;
  211. end
  212. -----------------------------------------------------------------------------
  213. -----------------------------------------------------------------------------
  214.  
  215.  
  216.